package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;


/**
 * Created by windo on 2015/11/24.
 */
public class LoginTask extends CouponHttpBaseTask {
    private String mLoginName;
    private String mLoginPwd;
    private String mAreaName;
    private String mChannel;

    public LoginTask(String loginName, String loginPwd) {
        super(TaskType.LOGIN_TASK);
        mLoginName = loginName;
        mLoginPwd = loginPwd;
//        mAreaName = areaName;
//        mChannel = generalizeChannel;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject json = response.getBody();
        EatShowUserInfo userInfo= null;
        if(json != null){
            userInfo = JSON.parseObject(json.toString(),EatShowUserInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS,userInfo);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if(mPhase == TASK_PHASE_INIT){
            CouponHttpRequest loginRequset = new CouponHttpRequest(RequestType.LOGIN_REQUEST);
            JSONObject jsonData = new JSONObject();
            jsonData.put("phoneNum",mLoginName);
            jsonData.put("pwd",mLoginPwd);
//            jsonData.put("areaName",mAreaName);
//            jsonData.put("generalizeChannel",mChannel);
            loginRequset.setData(jsonData.toString());
            loginRequset.setApiNo(ApiNo.LOGIN);
            addRequest(loginRequset);
        }
    }
}
